package com.food.eat.util;

import org.apache.tomcat.util.codec.binary.Base64;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;


/**
 * @Author:RenPu
 * @Date: 2020/7/19 17:36
 * @Version: 1.0
 * @description: 使用MD5对用户的密码，进行加密
 */
public class MD5Util {

    /**
     * MD5加密方法
     *
     * @param strValue
     * @return
     * @throws NoSuchAlgorithmException
     */
    public static String getMD5Str(String strValue) throws NoSuchAlgorithmException {

        MessageDigest md5 = MessageDigest.getInstance("MD5");

        String newStr = Base64.encodeBase64String(md5.digest(strValue.getBytes()));

        return newStr;
    }


    /**
     * 测试加密
     *
     * @param args
     * @throws NoSuchAlgorithmException
     */
    public static void main(String[] args) throws NoSuchAlgorithmException {

        String testMD = getMD5Str("456789713kl");
        System.out.println(testMD);

    }


}
